<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户名" prop="userid">
        <el-input
          v-model="queryParams.userid"
          placeholder="请输入用户名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
      <el-table-column label="用户名" align="center" prop="userid" />
      <el-table-column label="金额" align="center" prop="price" />
      <el-table-column label="开始时间" align="center" prop="stime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.stime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结束时间" align="center" prop="etime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.etime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status" :formatter="showStatus" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script setup>
import { listUser, getUser, delUser, addUser, updateUser } from "@/api/bydll/couponUser";

const { proxy } = getCurrentInstance();
const { sys_normal_disable } = proxy.useDict("sys_normal_disable");
  // 遮罩层
  const loading = ref(true);
  // 选中数组
  const ids = ref([]);
  // 非单个禁用
  const single = ref(true);
  // 非多个禁用
  const multiple = ref(true);
  // 显示搜索条件
  const showSearch = ref(true);
  // 总条数
  const total = ref(0);
  // 会员优惠券表格数据
  const userList = ref([]);
  // 弹出层标题
  const title = ref("");
  // 是否显示弹出层
  const open = ref(false);

const data = reactive({
  // 查询参数
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    userid: null,
    stime: null,
    etime: null,
    status: null,
  },
  // 表单参数
  form: {},
  // 表单校验
  rules: {
  }
});
const { queryParams, form, rules } = toRefs(data);
  /** 查询会员优惠券列表 */
  function getList() {
    loading.value = true;
    listUser(queryParams.value).then(response => {
      userList.value = response.rows;
      total.value = response.total;
      loading.value = false;
    });
  };
  /** 状态 */
function showStatus(row, column){
  if(row.status === '0'){
    return "未使用";
  }else if(row.status === '1'){
    return "已使用";
  }else if(row.status === '2'){
    return "过期";
  }
}
  // 取消按钮
  function cancel() {
    open.value = false;
    reset();
  };
  // 表单重置
  function reset() {
    form.value = {
      id: null,
      userid: null,
      price: null,
      stime: null,
      etime: null,
      status: null,
      addtime: null,
      updatetime: null
    };
    proxy.resetForm("form");
  };
  /** 搜索按钮操作 */
  function handleQuery() {
    queryParams.value.pageNum = 1;
    getList();
  };
  /** 重置按钮操作 */
  function resetQuery() {
    proxy.resetForm("queryForm");
    handleQuery();
  };
  getList()
</script>
